/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>分成记录列表</h3>
      </div>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>点击查看订单可查看订单详情</li>
          <li>列表可根据状态,订单号和生成日期查询</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>分成记录列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input class="searchinput" v-model="userId" size="small" placeholder="获佣用户ID" clearable />
        <el-input class="searchinput" v-model="orderSn" size="small" placeholder="订单编号" clearable />
        <el-date-picker
          style="width:150px"
          v-model="start_time"
          value-format="timestamp"
          size="small"
          placeholder="起始日期"
        ></el-date-picker>-
        <el-date-picker
          style="width:150px"
          v-model="end_time"
          value-format="timestamp"
          size="small"
          placeholder="截至日期"
        ></el-date-picker>
        <el-select v-model="status" size="small" clearable placeholder="状态">
          <el-option
            v-for="item in statusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="ID" prop="id" width="100"></el-table-column>
        <el-table-column label="获佣用户ID" width="170" show-overflow-tooltip>
          <template slot-scope="scope">
            <router-link
              :to="{name:'member_details',params:{user_id: scope.row.user_id}}"
            >{{scope.row.user_id}}</router-link>(
            <span v-if="scope.row.user">
              <span v-if="scope.row.user.nickname">{{scope.row.user.nickname}}</span>
              <span v-else-if="scope.row.user.email">{{scope.row.user.email}}</span>
              <span v-else>{{scope.row.user.mobile}}</span>
            </span>)
          </template>
        </el-table-column>
        <el-table-column label="订单编号" width="180">
          <template slot-scope="scope">
            <router-link
              :to="{name:'order_detail',params:{sn: scope.row.order_sn}}"
            >{{scope.row.order_sn}}</router-link>
          </template>
        </el-table-column>
        <el-table-column label="获佣金额" prop="money" width="120" :formatter="toFixedMoney"></el-table-column>
        <el-table-column label="获佣用户级别" prop="level_desc" width="150"></el-table-column>
        <el-table-column label="记录生成时间" prop="create_time_desc" width="180"></el-table-column>
        <el-table-column label="状态" prop="status_desc" width="80"></el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getRebateLogPage } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      statusList: [
        {
          value: 0,
          label: "未付款"
        },
        {
          value: 1,
          label: "已付款"
        },
        {
          value: 2,
          label: "等待分成"
        },
        {
          value: 3,
          label: "已分成"
        },
        {
          value: 4,
          label: "已取消"
        }
      ],
      status: null,
      userId: null,
      orderSn: null,
      start_time: null,
      end_time: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getRebateLogPage({
        user_id: this.userId,
        order_sn: this.orderSn,
        start_time: this.start_time ? this.start_time / 1000 : null,
        end_time: this.end_time ? this.end_time / 1000 : null,
        status: this.status,
        p: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        res.records.forEach(element => {
          element.distribut_proportion =
            Math.round((element.distribut / element.shop_price) * 10000) / 100 +
            "%";
        });
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    toFixedMoney(row) {
      return "￥" + row.money.toFixed(2);
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
